import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author YuanYuan
 * @Date 2022/9/25
 * @Time 21:17
 */
public class TestDemo2 {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger count = new AtomicInteger(0);
        Thread t1 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                //相当于count++
                count.getAndIncrement();
//                //相当于++count
//                count.incrementAndGet();
//                //相当于count--
//                count.getAndIncrement();
//                //相当于--count
//                count.decrementAndGet();
            }
        });
        Thread t2 = new Thread(()-> {
            for (int i = 0; i < 50000; i++) {
                //相当于count++
                count.getAndIncrement();
//                //相当于++count
//                count.incrementAndGet();
//                //相当于count--
//                count.getAndIncrement();
//                //相当于--count
//                count.decrementAndGet();
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();
        //get()获取到内部的值
        System.out.println(count.get());
    }
}
